﻿@{
    ViewBag.Title = "Dir";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@using System.Collections;

<script language="JavaScript" src="/content/js/jquery.imgpreview.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var obj = $("#imgPreview a[rel]");
            if (obj.length > 0) {
                $('#imgPreview a[rel]').imgPreview({
                    srcAttr: 'rel',
                    imgCSS: { width: 200 }
                });
            }
        });
    </script>
    <div class="subnav">
        <div class="content-menu ib-a blue line-x">
            <a href='/attachment/index' class="add fb"><em>切换至数据库模式</em></a>
            <span>|</span><a href='javascript:;' class="on"><em>附件管理</em></a>
        </div>
    </div>
    <div class="bk15">
    </div>
    <div class="pad-lr-10">
        <table width="100%" cellspacing="0" class="search-form">
            <tbody>
                <tr>
                    <td>
                        <div class="explain-col">
                            <a href="/admin/attachment/index">切换至数据库模式</a>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="pad-lr-10">
        <div class="table-list">
            <table width="100%" cellspacing="0" id="imgPreview">
                <tr>
                    <td align="left">
                        当前目录：@Html.Raw(Request.QueryString["dir"])/
                    </td>
                    <td width="10%">
                    </td>
                </tr>
                @if (Request.QueryString["dir"].ToLower() != "upload")
                {
                <tr>
                    <td align="left">
                        <img src="/content/img/folder-closed.gif" />
                        <a href="javascript:history.back();">返回上一级目录</a>
                    </td>
                    <td width="10%">
                    </td>
                </tr>
                }
                @foreach (string item in (ViewData["folderlist"] as ArrayList))
                {
                <tr>
                    <td align="left">
                        <img src="/content/img/folder-closed.gif" />
                        <a href="?dir=<%=Request.QueryString["dir"]%>/<%= item %>"><b>
                            <%= item %></b></a>
                    </td>
                    <td width="10%">
                    </td>
                </tr>
                }
                @foreach (string item in (ViewData["filelist"] as ArrayList))
                {
                <tr>
                    <td align="left" onclick="javascript:album_cancel(this)">
                        <img src="/content/img/ext/@Html.Raw(item.Substring(item.LastIndexOf(".") + 1) + ".gif")" />
                        <a href="javascript:;" rel="/@Html.Raw(Request.QueryString["dir"] + "/" + item)">
                            <%=item %></a>
                    </td>
                    <td width="10%">
                    <a href="javascript:preview('/@Html.Raw(Request.QueryString["dir"] + "/" + item)')">
                                预览</a> | <a href="javascript:;" onclick="att_delete(this,'@item','@Html.Raw(Request.QueryString["dir"])/')">删除</a>
                    </td>
                </tr>
                }
            </table>
        </div>
    </div>
    <script type="text/javascript">
        function preview(filepath) {
            if (IsImg(filepath)) {
                window.top.art.dialog({ title: '预览', fixed: true, content: '<img src="' + filepath + '" />', time: 8 });
            } else {
                window.top.art.dialog({ title: '预览', fixed: true, content: '<a href="' + filepath + '" target="_blank"/><img src="/content/img/admin_img/down.gif">单击打开</a>' });
            }
        }
        function att_delete(obj, filename, locationdir) {
            window.top.art.dialog({ content: '确认删除吗？', fixed: true, style: 'confirm', id: 'att_delete' },
	function () {
	    $.get('/attachment/deletebyname?atname=' + filename + '&dir=' + locationdir, function (data) {
	        if (data == "1") {
	            $(obj).parent().parent().fadeOut("slow");
	        }
	    })

	},
	function () { });
        };
        function IsImg(url) {
            var sTemp;
            var b = false;
            var opt = "jpg|gif|png|bmp|jpeg";
            var s = opt.toUpperCase().split("|");
            for (var i = 0; i < s.length; i++) {
                sTemp = url.substr(url.length - s[i].length - 1);
                sTemp = sTemp.toUpperCase();
                s[i] = "." + s[i];
                if (s[i] == sTemp) {
                    b = true;
                    break;
                }
            }
            return b;
        }

    </script>
